<template>
  <div class="app-container">
    <div class="change">
      <p>
        <span>产品名称</span>
        <el-input v-model="tempData.xtitle" :disabled="islook" type="text" class="userselect" placeholder="请输入产品名称"/>
      </p>
      <p>
        <span>产品描述</span>
        <el-input v-model="tempData.xcontent" :disabled="islook" type="textarea" class="userselect" placeholder="请输入反馈内容" />
      </p>
      <p>
        <span>提交人</span>
        <el-input v-model="tempData.xperson" :disabled="islook" type="text" class="userselect" placeholder="请输入提交人" />
      </p>
      <p>
        <span>图片1</span>
        <el-upload
          class="avatar-uploader"
          action
          :http-request="designUpAvatar1"
          :show-file-list="false"
					:disabled="islook"
        >
          <img v-if="tempData.ximgurl1" :src="tempData.ximgurl1" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </p>
      <p>
        <span>图片2</span>
        <el-upload
          class="avatar-uploader"
          action
          :http-request="designUpAvatar2"
          :show-file-list="false"
					:disabled="islook"
        >
          <img v-if="tempData.ximgurl2" :src="tempData.ximgurl2" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </p>
      <p>
        <span>图片3</span>
        <el-upload
          class="avatar-uploader"
          action
          :http-request="designUpAvatar3"
          :show-file-list="false"
					:disabled="islook"
        >
          <img v-if="tempData.ximgurl3" :src="tempData.ximgurl3" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </p>
    </div>
		<div class="submits">
		  <div class="save" @click="save" v-if="!islook">保存</div>
		  <div class="nosave" @click="nosave" v-if="!islook">取消</div>
			<div class="save" @click="back" v-if="islook">返回</div>
		</div>
  </div>
</template>

<script>
	import { addXcxPro,updateXcxPro, } from '@/api/oneclassify'
	import { uploadFile } from '@/api/people'
	export default {
		data(){
			return{
				tempData: {},
				writeOradd: 0,   //1修改还是0增加
				islook: false
			}
		},
		mounted() {
			// console.log(this.$route.params)
			if(this.$route.params.look){
				this.islook = true
			}
			if(this.$route.params.options){
				this.tempData = JSON.parse(this.$route.params.options)
				this.writeOradd = 1
			}else{
				this.writeOradd = 0
			}
			console.log(this.tempData)
		},
		methods:{
			save(){
				if(this.writeOradd == 0){
					addXcxPro(this.tempData).then(res => {
						console.log(res)
						this.$message({
							message: res.message,
							type: 'success'
						})
					})
				}else{
					delete this.tempData.insertTime
					delete this.tempData.updateTime
					updateXcxPro(this.tempData).then(res => {
						console.log(res)
						this.$message({
							message: res.message,
							type: 'success'
						})
					})
				}
				this.$router.go(-1)
			},
			nosave(){
				this.$router.go(-1)
			},
			back(){
				this.$router.go(-1)
			},
			// 上传头像
			designUpAvatar1(item){
				console.log(this.fileNum)
				var formData = new FormData()
				formData.append("file", item.file)
				uploadFile(formData).then(res => {
				  console.log(res)
					this.$message({
					  showClose: true,
					  message: '添加成功',
					  type: "success"
					})
					// this.imageUrl = res
					this.tempData.ximgurl1 = res
					this.$forceUpdate()
				})
      },
      designUpAvatar2(item){
				console.log(this.fileNum)
				var formData = new FormData()
				formData.append("file", item.file)
				uploadFile(formData).then(res => {
				  console.log(res)
					this.$message({
					  showClose: true,
					  message: '添加成功',
					  type: "success"
					})
					// this.imageUrl = res
					this.tempData.ximgurl2 = res
					this.$forceUpdate()
				})
      },
      designUpAvatar3(item){
				console.log(this.fileNum)
				var formData = new FormData()
				formData.append("file", item.file)
				uploadFile(formData).then(res => {
				  console.log(res)
					this.$message({
					  showClose: true,
					  message: '添加成功',
					  type: "success"
					})
					// this.imageUrl = res
					this.tempData.ximgurl3 = res
					this.$forceUpdate()
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.disable{
		pointer-events: none;
		background: #808080 !important;
	}
	.change {
	  display: flex;
	  flex-wrap: wrap;
	  background: #fff;
	  border-radius: 8px;
	  padding: 20px 0;
	  > p {
	    width: 33%;
	    font-size: 14px;
	    display: flex;
	    align-items: center;
	    color: #333;
	    /deep/.el-input__inner {
	      // width: inherit;
	      background: none;
	      height: 32px;
	      // line-height: 32px;
	      color: #333;
	      border: 1px solid rgba(0, 0, 0, 0.1);
	      padding: 0 25px;
	    }
	    /deep/.el-input__icon {
	      line-height: 32px;
	    }
	    .userselect {
	      // max-width: 250px;
	      flex: 1;
	    }
	
	    > span {
	      display: block;
	      width: 100px;
	      text-align: right;
	      padding-right: 15px;
	    }
	    > input {
	      width: inherit;
	      flex: 1;
	      height: 32px;
	      border-radius: 3px;
	      border: 1px solid rgba(0, 0, 0, 0.1);
	      padding-left: 10px;
	      color: #333;
	    }
			> textarea{
				width: inherit;
				flex: 1;
				height: 60px;
				border-radius: 3px;
				border: 1px solid rgba(0, 0, 0, 0.1);
				padding: 10px;
			}
	  }
	}
	.avatar-uploader .el-upload {
	  border: 1px dashed #999 !important;
	  border-radius: 6px;
	  cursor: pointer;
	  position: relative;
	  overflow: hidden;
	  width: 100%;
	}
	.avatar-uploader .el-upload:hover {
	  border-color: #409eff;
	}
	
	.avatar-uploader-icon {
	  font-size: 28px;
	  color: #8c939d;
	  width: 100px;
	  height: 100px;
	  line-height: 100px;
	  text-align: center;
    border: 1px solid #ccc;
	}
	.avatar {
	  width: 100px;
	  height: 100px;
	  display: block;
	}
	.submits {
	  display: flex;
		background: #fff;
	  padding: 20px 20px;
		border-radius: 8px;
		margin-top: 20px;
		// border-top: 1px solid #ccc;
	  justify-content: flex-end;
	  align-items: center;
	  > div {
	    width: 80px;
	    height: 32px;
	    text-align: center;
	    line-height: 32px;
	    color: #fff;
	    font-size: 14px;
	    border-radius: 4px;
	    margin-left: 30px;
	    cursor: pointer;
	  }
	  .save {
	    background: #18a05e;
	  }
	  .nosave {
	    background: #999;
	  }
	}
</style>